<template>
    <div class="managerHomePage">
        <!-- 超级管理员首页  左侧  模块 -->
        <div class="leftContainer">
            <!-- 租户管理员 -->
            <div class="repository">
                <div class="title">
                    <span class="text">租户管理员</span>
                </div>
                <div class="listBox">
                    <ul>
                        <div class="listLine"></div>
                        <li v-for="(item, index) in tenantManager" :key="index">
                            <span class="circleBox blueCirle"></span>
                            <i class="trainingDate">
                                <i class="date">{{ item.lesseeCode }}</i>
                            </i>
                            <i class="trainingDate">
                                <i class="date">{{ item.lesseeName }}</i>
                            </i>
                            <i class="trainingServe">{{ item.linkMobile }}</i>
                            <i class="trainingServe">{{ item.ctiNum }}</i>
                            <i class="trainingServeRight">{{ item.createTime }}</i>
                        </li>
                    </ul>
                </div>
                <div class="more" v-if="true">
                    <el-button size="small" type="text" @click="tenantManageMore">更多>></el-button>
                </div>
            </div>
        </div>

        <!-- 超级管理员首页  中间  模块 -->
        <div class="middleContainer">
            <!-- 备忘录模块 -->
            <div class="memorandum">
                <el-row>
                    <el-col :span="19">
                        <div class="title">备忘录</div>
                    </el-col>
                    <el-col :span="5">
                        <el-button
                            size="small"
                            type="text"
                            @click="addMemoClick"
                            style="font-size: 16px"
                        >新 增</el-button>
                    </el-col>
                </el-row>
                <div class="listBox">
                    <ul>
                        <div class="listLines"></div>
                        <li
                            v-for="(item, index) in memoData"
                            :key="index"
                            style="cursor: pointer"
                            @click="viewMemoContent(item)"
                        >
                            <span
                                :class="
                  item.isLatest ? 'circleBox redCirle' : 'circleBox blueCirle'
                "
                            ></span>
                            <i class="noticeServe" style="width: 30%">
                                {{
                                item.notesTitle
                                }}
                            </i>
                            <i style="width: 50%">
                                <span :class="item.isLatest ? 'date redColor' : 'date'">
                                    {{
                                    item.remindTime
                                    }}
                                </span>
                            </i>
                        </li>
                    </ul>
                </div>
                <div class="more">
                    <el-button size="small" type="text" @click="memoMoreClick">更多>></el-button>
                </div>
            </div>
        </div>

        <!-- 超级管理员首页  右侧  模块 -->
        <div class="rightContainer">
            <div class="title">账号信息</div>
            <div class="mainBox">
                <div class="topBox">
                    <div class="bgm">
                        <img src="@/assets/img/home/userInfoBackground.png" alt class="userInfoBg" />
                    </div>
                    <div class="headerImgBox">
                        <img src="@/assets/img/home/rahmen.png" alt class="bgImg" />
                        <img src="@/assets/img/home/headerImg.png" alt class="headerImg" />
                    </div>
                    <div class="userInfo">
                        <div class="info" :title="userInfo.userName">
                            <span>姓名：</span>
                            {{ userInfo.userName }}
                        </div>

                        <div class="info" :title="userInfo.userAccount">
                            <span>坐席工号：</span>
                            {{ userInfo.userAccount }}
                        </div>
                        <!-- <div class="info" :title="userInfo.agNum">
                            <span>CTI工号：</span>{{ userInfo.ctiNum }}
                        </div>
                        <div class="info" :title="userInfo.extensionNum">
                            <span>分机号：</span>{{ userInfo.extensionNum }}
                        </div>
                        <div class="info" :title="userInfo.extensionNum">
                            <span>操作员号：</span>{{ userInfo.agNum }}
                        </div>-->
                    </div>
                </div>
            </div>
        </div>
        <!--备忘录更多-->
        <el-dialog
            v-drag
            :close-on-click-modal="false"
            :visible.sync="memoMoreDialog"
            append-to-body
            center
            width="950px"
        >
            <div slot="title">备忘录管理</div>
            <el-form
                :inline="true"
                class="menu-setting demo-form-inline"
                :model="memoFormData"
                ref="memoFormData"
                size="small"
            >
                <el-form-item label="标题">
                    <el-input v-model="memoFormData.notesTitle" placeholder="请输入标题"></el-input>
                </el-form-item>
                <el-form-item label="内容">
                    <el-input v-model="memoFormData.notesContent" placeholder="请输入内容"></el-input>
                </el-form-item>
                <el-button
                    type="primary"
                    size="small"
                    icon="el-icon-search"
                    @click="hanlesearch"
                    :loading="searchLoading"
                >查 询</el-button>
                <el-button
                    type="primary"
                    size="small"
                    icon="el-icon-refresh-right"
                    @click="handleReset"
                    :loading="resetLoading"
                >重 置</el-button>
            </el-form>
            <el-table :data="memoMoreData" width="100%" stripe border class="heard-bg">
                <el-table-column label="标题" prop="notesTitle" width="180" show-overflow-tooltip></el-table-column>
                <el-table-column label="内容" prop="notesContent" width="300" show-overflow-tooltip></el-table-column>
                <el-table-column label="提醒时间" prop="remindTime"></el-table-column>
                <el-table-column label="操作">
                    <template slot-scope="scope">
                        <el-button
                            type="primary"
                            icon="el-icon-edit"
                            circle
                            title="编辑"
                            @click="handleEdit(scope.row)"
                        />
                        <el-button
                            type="danger"
                            icon="el-icon-delete"
                            circle
                            title="删除"
                            @click="handleDelete(scope.row)"
                        />
                    </template>
                </el-table-column>
            </el-table>
            <!-- 分页 -->
            <div class="pagination">
                <Pagination
                    :hanleChangeCurrentPage="hanleChangeCurrentPageMemo"
                    :handleChangeSize="handleChangeSizeMemo"
                    :currentPage="currentPageMemo"
                    :pageSize="pageSizeMemo"
                    :total="totalMemo"
                />
            </div>
        </el-dialog>
        <!--新增/编辑/查看备忘录-->
        <el-dialog
            v-drag
            :close-on-click-modal="false"
            :visible.sync="addMemoDialog"
            append-to-body
            center
            width="600px"
        >
            <div slot="title">{{ EditTitle }}</div>
            <el-form
                label-width="90px"
                class="menu-setting"
                :model="rowData"
                :rules="formRules"
                ref="memoFormData"
                size="small"
            >
                <el-form-item label="标题：" prop="notesTitle">
                    <el-input
                        v-model="rowData.notesTitle"
                        style="width: 100%"
                        :disabled="flag"
                        placeholder="请输入标题"
                    ></el-input>
                </el-form-item>
                <el-form-item label="内容：" prop="notesContent">
                    <el-input
                        type="textarea"
                        rows="5"
                        maxlength="200"
                        v-model="rowData.notesContent"
                        :disabled="flag"
                        style="width: 100%"
                        placeholder="请输入内容"
                    ></el-input>
                </el-form-item>
                <el-form-item label="提醒时间：">
                    <el-date-picker
                        :disabled="flag"
                        style="width: 100%"
                        v-model="rowData.remindTime"
                        type="datetime"
                        placeholder="请选择提醒时间"
                        value-format="yyyy-MM-dd HH:mm:ss"
                        format="yyyy-MM-dd HH:mm:ss"
                        :picker-options="{
              disabledDate: (time) => {
                return time.getTime() < Date.now() - 3600 * 1000 * 24;
              },
            }"
                    ></el-date-picker>
                </el-form-item>
            </el-form>
            <div slot="footer" class="dialog-footer">
                <el-button
                    size="small"
                    @click="addMemoDialog = false"
                    v-if="!flag"
                    class="cancelBtn"
                >取 消</el-button>
                <el-button
                    type="primary"
                    size="small"
                    @click="submitEditMemo"
                    v-if="!flag"
                    class="submitBtn"
                    icon="el-icon-circle-check"
                >确定</el-button>
            </div>
        </el-dialog>
    </div>
</template>
<script>
import moment from 'moment';
import Pagination from '@/components/Pagination/Pagination.vue';
import { getToken } from '@/utils/auth';

export default {
    name: 'managerHome',
    components: {
        Pagination,
    },
    data() {
        return {
            memoFormData: { // 备忘录查询
                notesTitle: '',
                notesContent: '',
                remindTime: '',
            },
            formRules: {
                notesTitle: [
                    { required: true, message: '请输入备忘录标题', trigger: 'blur' },
                ],
                notesContent: [
                    { required: true, message: '请输入备忘录内容', trigger: 'blur' },
                ],
            },
            startTimeRange: '',
            rowData: {
                notesTitle: '',
                notesContent: '',
                remindTime: '',
            },
            // 当前页码
            currentPageMemo: 0,
            // 页码大小
            pageSizeMemo: 10,
            // 总数
            totalMemo: 0,
            addMemoDialog: false,
            memoMoreDialog: false,
            resetLoading: false,

            // 呼叫历史数据
            callhistory: [],
            EditTitle: '',
            searchLoading: false,
            defaultCardInfo: this.$store.getters.cardInfo_3004, // 信用卡信息 可以用多卡 3004按卡号查询卡资料信息
            formData: [],
            // 租户管理员列表
            tenantManager: [],
            memoData: [],
            memoMoreData: [],
            flag: false,

        };
    },
    mounted() {
        this.getInitData(this.formData);
        // 备忘录列表
        this.getInitMemoData();
    },
    watch: {
        'rowData.remindTime': {
            handler(newValue, oldValue) {
                if (newValue) {
                    const nowDate = moment().format('yyyy-MM-DD HH:mm:ss');
                    const dt = nowDate.split(' ');
                    let st = '';
                    if (newValue.split(' ')[0] === dt[0]) {
                        st = dt[1];
                    } else {
                        st = '00:00:00';
                    }
                    this.startTimeRange = `${st} - 23:59:59`;
                }
            },
        },
    },
    computed: {
        userInfo() {
            return this.$store.getters.userInfo;
        },
        getVXcardInfo_3004() {
            return this.$store.getters.cardInfo_3004;
        },
    },
    methods: {
        tenantManageMore() {
            this.$router.push({ path: '/index/lesseeManagement' });
        },
        // 获取租户表格数据
        getInitData(form) {
            let params = {
                pageNum: this.currentPage,
                pageSize: this.pageSize,
            };
            params = Object.assign({}, params, form);
            this.$post.Lessee.searchLessee(params)
                .then((res) => {
                    if (res.data.success) {
                        // console.log(res.data)
                        this.tenantManager = res.data.content.lesseeList;
                        this.total = res.data.content.lesseeCount;
                    }
                });
        },
        viewMemoContent(row) {
            this.EditTitle = '查看备忘录';
            this.rowData = Object.assign({}, this.memoFormData, row);
            this.addMemoDialog = true;
            this.flag = true;
            if (this.$refs.memoFormData) {
                this.$refs.memoFormData.resetFields();
            } else {
                this.$nextTick(() => {
                    // this.$refs.memoFormData.resetFields();
                });
            }
        },
        // 备忘录更多
        memoMoreClick() {
            this.memoMoreDialog = true;
            this.getMemoData(2, this.memoFormData);
        },
        hanlesearch() {
            this.getMemoData(2, this.memoFormData);
        },
        // 备忘录列表
        getInitMemoData() {
            this.memoFormData = {};
            this.getMemoData(1, this.memoFormData);
        },

        // 备忘录查询
        getMemoData(data, form) {
            let pageNum = 1;
            let pageSize = 10;
            if (data === 1) {
                pageNum = 1;
                pageSize = 10;
            } else {
                pageNum = this.currentPageMemo;
                pageSize = this.pageSizeMemo;
            }
            let params = {
                pageNum,
                pageSize,
                agentNo: JSON.parse(getToken()).userAccount,
            };
            params = Object.assign({}, params, form);
            this.$post.MemoMangage.searchByPage(params)
                .then((res) => {
                    if (res.data.success) {
                        if (data === 1) {
                            this.memoData = res.data.content.recordList;
                        }
                        this.memoMoreData = res.data.content.recordList;
                        this.totalMemo = res.data.content.recordCount;
                    }
                });
        },
        // 备忘录重置
        handleReset() {
            this.memoFormData = {
                notesTitle: '',
                notesContent: '',
                remindTime: '',
            };
            this.getMemoData(2, this.memoFormData);
        },
        // 添加备忘录
        addMemoClick() {
            this.EditTitle = '新增备忘录';
            this.rowData = Object.assign({}, this.memoFormData);
            this.addMemoDialog = true;
            this.flag = false;
            // 解决一进来就进行表单验证问题
            if (this.$refs.memoFormData) {
                this.$refs.memoFormData.resetFields();
            } else {
                this.$nextTick(() => {
                    // this.$refs.memoFormData.resetFields();
                });
            }
        },
        // 编辑备忘录
        handleEdit(row) {
            this.EditTitle = '编辑备忘录';
            this.rowData = Object.assign({}, this.memoFormData, row);
            this.addMemoDialog = true;
            this.flag = false;
            if (this.$refs.memoFormData) {
                this.$refs.memoFormData.resetFields();
            } else {
                this.$nextTick(() => {
                    // this.$refs.memoFormData.resetFields();
                });
            }
        },
        // 添加编辑备忘录确定
        submitEditMemo() {
            if (this.rowData.id) {
                // 编辑
                this.$refs.memoFormData.validate((valid) => {
                    if (valid) {
                        this.$post.MemoMangage.updateNotes(this.rowData)
                            .then((res) => {
                                if (res.data.success) {
                                    this.$message.success('修改成功！');
                                    this.getMemoData(2, this.memoFormData);
                                    this.addMemoDialog = false;
                                } else {
                                    this.$message.error(res.data.msg);
                                }
                            });
                    } else {
                        this.$message.warning('请完成表单填写！');
                    }
                });
            } else {
                // 添加
                this.$refs.memoFormData.validate((valid) => {
                    if (valid) {
                        this.$post.MemoMangage.addNotes(this.rowData)
                            .then((res) => {
                                if (res.data.success) {
                                    this.$message.success('添加成功！');
                                    this.getInitMemoData();
                                    this.addMemoDialog = false;
                                } else {
                                    this.$message.error(res.data.msg);
                                }
                            });
                    } else {
                        this.$message.warning('请完成表单填写！');
                    }
                });
            }
        },
        // 删除备忘录
        handleDelete(row) {
            this.$confirm('确认删除该备忘录？', '提示', { customClass: 'warning', type: 'warning' })
                .then(() => {
                    this.$post.MemoMangage.deleteNotes({ id: row.id })
                        .then((res) => {
                            if (res.data.success) {
                                this.$message.success('删除成功！');
                                if (this.memoMoreData.length === 1) {
                                    this.currentPageMemo = this.currentPageMemo - 1;
                                }
                                this.getMemoData(2, this.memoFormData);
                            } else {
                                this.$message.error(res.data.msg);
                            }
                        });
                })
                .catch(() => {
                });
        },
        // 页码切换方法
        hanleChangeCurrentPageMemo(val) {
            this.currentPageMemo = val;
            this.getMemoData(2, this.memoFormData);
        },
        // 切换分页大小方法
        handleChangeSizeMemo(val) {
            this.pageSizeMemo = val;
            this.getMemoData(2, this.memoFormData);
        },
    },
};
</script>
<style lang="scss" scoped>
.pagination {
    margin-top: 20px;
    text-align: right;
}
.managerHomePage {
    display: flex;
    justify-content: space-between;
    overflow: hidden;
    max-height: 100%;
    .title {
        color: #333;
        font-size: 16px;
        line-height: 18px;
        margin-bottom: 24px;
        text-align: left;
    }
    .leftContainer,
    .middleContainer,
    .rightContainer {
        float: left;
        min-height: 100%;
        .more {
            margin-top: 10px;
            text-align: right;
            font-size: 12px;
            position: absolute;
            right: 10px;
            bottom: 20px;
        }
    }
    .listBox {
        width: 100%;
        height: 90%;
        position: relative;

        ul {
            position: relative;
            left: 0;
            z-index: 1;
            overflow: hidden;
            max-height: 240px;

            .listLine {
                width: 1px;
                height: 100%;
                background: #dae6ff;
                position: absolute;
                left: 3px;
                top: 17px;
                z-index: -10;
            }
            .listLines {
                width: 1px;
                height: 100%;
                background: #dae6ff;
                position: absolute;
                left: 4px;
                top: 17px;
                z-index: -10;
            }
            li {
                list-style: none;
                text-align: left;
                font-size: 14px;
                line-height: 30px;
                color: #333;
                z-index: 1;

                .circleBox {
                    position: relative;
                    display: inline-block;
                    width: 8px;
                    height: 8px;
                    border-radius: 50%;
                    background: #fff;
                    margin-right: 8px;
                }
                .blueCirle {
                    border: 1px solid #dae6ff;
                }
                .redCirle {
                    border: 1px solid red;
                }
                i {
                    font-style: normal;
                    display: inline-block;
                }
                .trainingDate {
                    // width: 25%;

                    .date {
                        margin-right: 6px;
                    }

                    .date.redColor {
                        color: red;
                    }

                    .dot {
                        width: 6px;
                        height: 6px;
                        background-color: red;
                        border-radius: 50%;
                        display: inline-block;
                        margin-bottom: 5px;
                    }
                }
                .trainingUser {
                    width: 10%;
                }
                .trainingServe {
                    // width: 35%;
                    margin-left: 15%;
                }
                .trainingServeRight {
                    float: right;
                    margin-right: 5%;
                }
                .noticeServe {
                    width: 57%;
                    overflow: hidden;
                    white-space: nowrap;
                    text-overflow: ellipsis;
                    vertical-align: middle;
                    margin: 0 5%;
                }
                .rightBtn {
                    width: 64px;
                    height: 24px;
                    line-height: 12px;
                    padding: 6px 11px;
                    border: 1px solid #8ad7cd;
                    border-radius: 5px;
                    float: right;
                    margin-right: 0;
                    text-align: center;
                }

                .icon {
                    float: right;
                    width: 16px;
                    height: 16px;
                    margin-top: 9px;
                    cursor: pointer;

                    img {
                        display: block;
                        width: 100%;
                        height: 100%;
                    }
                }
                .trainingUnSucess {
                    background: #fff;
                    color: #8ad7cd;
                }
                .trainingSucess {
                    background: #8ad7cd;
                    color: #fff;
                }
            }
        }
    }
    // 左侧容器样式
    .leftContainer {
        flex: 2.4;
        min-width: 400px;
        margin-right: 12px;

        // 知识库更新内容模块样式
        .repository {
            background-color: #fff;
            border-radius: 8px;
            padding: 24px;
            height: 100%;
            overflow: hidden;
            margin-bottom: 16px;
            position: relative;
        }

        // 坐席信息模块样式
        .training {
            width: 100%;
            height: 335px;
            padding: 24px;
            box-sizing: border-box;
            background-color: #fff;
            border-radius: 8px;
            overflow: hidden;
        }
    }

    // 中间容器样式
    .middleContainer {
        flex: 1.6;
        min-width: 370px;
        margin-right: 12px;

        .memorandum {
            background-color: #fff;
            border-radius: 8px;
            padding: 24px;
            height: 100%;
            overflow: hidden;
            margin-bottom: 16px;
            position: relative;

            .listBox {
                .trainingDate {
                    width: 70px !important;
                    margin-right: 40px;
                }

                ul {
                    max-height: 390px;
                }

                .trainingServe {
                    margin-left: 0 !important;
                    width: 60% !important;
                    font-style: normal;
                }
                .listLine {
                    width: 1px;
                    height: 100%;
                    background: #dae6ff;
                    position: absolute;
                    left: 3px;
                    top: 17px;
                    z-index: -10;
                }
                .listLines {
                    width: 1px;
                    height: 100%;
                    background: #dae6ff;
                    position: absolute;
                    left: 4px;
                    top: 17px;
                    z-index: -10;
                }
            }
        }

        .qualityTesting {
            background-color: #fff;
            border-radius: 8px;
            padding: 24px 16px;
            height: 355px;

            .title {
                margin-left: 8px;
            }
        }
    }

    .rightContainer {
        flex: 1;
        min-width: 233px;
        background-color: #fff;
        height: 887px;
        border-radius: 8px;
        padding: 24px 16px;

        .title {
            color: #333;
            font-size: 16px;
            line-height: 18px;
            margin-bottom: 24px;
            text-align: left;
        }

        .mainBox {
            .topBox {
                position: relative;
                height: 250px;
                overflow: hidden;
                box-sizing: border-box;
                border: 1px solid #dae6ff;
                border-radius: 8px;

                .bgm {
                    position: absolute;
                    top: 0;
                    left: 0;
                    width: 100%;
                    height: 145px;
                    border-radius: 8px;
                    overflow: hidden;

                    .userInfoBg {
                        display: block;
                        height: 100%;
                        width: 100%;
                    }
                }

                .headerImgBox {
                    position: absolute;
                    top: 100px;
                    left: 50%;
                    transform: translateX(-50%);
                    width: 72px;
                    height: 72px;

                    .bgImg {
                        position: absolute;
                        top: 0;
                        left: 0;
                        width: 100%;
                        height: 100%;
                        z-index: 9;
                    }

                    .headerImg {
                        position: absolute;
                        left: 50%;
                        top: 50%;
                        transform: translate(-50%, -50%);
                        width: 58px;
                        height: 58px;
                        border-radius: 50%;
                        z-index: 1;
                    }
                }

                .userInfo {
                    position: absolute;
                    bottom: 0;
                    left: 0;
                    width: 100%;
                    padding: 0 12px;

                    .info {
                        font-size: 16px;
                        height: 24px;
                        line-height: 14px;
                        margin-bottom: 12px;
                        text-align: left;
                        width: 100%;
                        color: #333;
                        font-weight: 600;
                        span {
                            display: inline-block;
                            width: 50%;
                            text-align: right;
                            color: #666;
                            font-weight: normal;
                        }
                    }
                }
            }
        }
    }
}
</style>
